﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:ForumsClient="clr-namespace:Microsoft.Forums.ForumsClient"
    xmlns:l='clr-namespace:Microsoft.Forums.ForumsClient.Views' >
    <!-- Contains the styles and templates for the Threaded view for posts -->

    <!-- Type converter to convert from level number to indent amount-->
    <l:LevelToIndentConverter x:Key="LevelToIndentConverter" />

    <!-- Type converter to convert the number of replies to true if greater than zero-->
    <l:GreaterThanZeroToTrueConverter x:Key="GreaterThanZeroConverter" />

    <!-- Type converter to convert the status of a post or rootpost to images-->
    <l:ThreadPostStatusConverter x:Key="ThreadPostStatusConverter" />

    <!-- Hierarchical data template to indicated how to display child posts-->
    <HierarchicalDataTemplate x:Key="PostHierarchy" ItemsSource="{Binding Path=ChildPosts}" />

    <!-- Templated for Up and Down Arrows-->
    <DataTemplate x:Key="HeaderTemplateArrowUp">
        <DockPanel>
            <TextBlock HorizontalAlignment="Center" Text="{Binding}"/>
        <Path x:Name="arrow"
           StrokeThickness = "1"                                     
           Fill = "gray"
           Data = "M 5,10 L 15,10 L 10,5 L 5,10"/>
     </DockPanel>
    </DataTemplate>

    <DataTemplate x:Key="HeaderTemplateArrowDown">
        <DockPanel>
            <TextBlock HorizontalAlignment="Center" Text="{Binding}"/>
        <Path x:Name="arrow"
              StrokeThickness = "1"                                  
              Fill = "gray"
              Data = "M 5,5 L 10,10 L 15,5 L 5,5"/>
      </DockPanel>
    </DataTemplate>

    <!-- The style for the expand or collapse toggle button -->
    <Style x:Key="ExpandCollapseToggleStyle"
           TargetType="{x:Type ToggleButton}">
        <Setter Property="Focusable"
              Value="False"/>
        <Setter Property="Width"
              Value="19"/>
        <Setter Property="Height"
              Value="13"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ToggleButton}">
                    <Border Width="19"
                    Height="13"
                    Background="Transparent">
                        <Border Width="9"
                      Height="9"
                      BorderThickness="1"
                      BorderBrush="#FF7898B5"
                      CornerRadius="1"
                      SnapsToDevicePixels="true">
                            <Border.Background>
                                <LinearGradientBrush StartPoint="0,0"
                                       EndPoint="1,1">
                                    <LinearGradientBrush.GradientStops>
                                        <GradientStop Color="White"
                                    Offset=".2"/>
                                        <GradientStop Color="#FFC0B7A6"
                                    Offset="1"/>
                                    </LinearGradientBrush.GradientStops>
                                </LinearGradientBrush>
                            </Border.Background>
                            <Path x:Name="ExpandPath"
                      Margin="1,1,1,1"
                      Fill="Black"
                      Data="M 0 2 L 0 3 L 2 3 L 2 5 L 3 5 L 3 3 L 5 3 L 5 2 L 3 2 L 3 0 L 2 0 L 2 2 Z"/>
                        </Border>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsChecked"
                       Value="True">
                            <Setter Property="Data"
                        TargetName="ExpandPath"
                        Value="M 0 2 L 0 3 L 5 3 L 5 2 Z"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <!-- Template for an individual columns tree view item, includes a gridviewrowpresenter to add columns -->
    <Style TargetType="{x:Type l:ColumnsTreeViewItem}">
        <Setter Property="FontWeight" Value="Bold" />
        <Setter Property="IsExpanded" Value="{Binding Path=AreChildrenDisplayed, Mode=TwoWay}" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type l:ColumnsTreeViewItem}">
                    <StackPanel>
                        <Border Name="Bd"
                      Background="{TemplateBinding Background}"
                      BorderBrush="{TemplateBinding BorderBrush}"
                      BorderThickness="{TemplateBinding BorderThickness}"
                      Padding="{TemplateBinding Padding}">
                            <GridViewRowPresenter x:Name="PART_Header"
                                      Content="{TemplateBinding Header}" 
                                      Columns="{Binding Path=Columns,RelativeSource={RelativeSource AncestorType={x:Type l:ColumnsTreeView}}}" />
                        </Border>
                        <ItemsPresenter x:Name="ItemsHost" />
                    </StackPanel>
                    <ControlTemplate.Triggers>
                        <DataTrigger Binding="{Binding Path=Post.PostPropertySet.IsRead}" Value="True">
                            <Setter Property="FontWeight" Value="Normal" />
                        </DataTrigger>
                        <Trigger Property="IsExpanded"
                       Value="false">
                            <Setter TargetName="ItemsHost"
                        Property="Visibility"
                        Value="Collapsed"/>
                        </Trigger>
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="HasHeader"
                             Value="false"/>
                                <Condition Property="Width"
                             Value="Auto"/>
                            </MultiTrigger.Conditions>
                            <Setter TargetName="PART_Header"
                        Property="MinWidth"
                        Value="75"/>
                        </MultiTrigger>
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="HasHeader"
                             Value="false"/>
                                <Condition Property="Height"
                             Value="Auto"/>
                            </MultiTrigger.Conditions>
                            <Setter TargetName="PART_Header"
                        Property="MinHeight"
                        Value="19"/>
                        </MultiTrigger>
                        <Trigger Property="IsSelected"
                       Value="true">
                            <Setter TargetName="Bd"
                        Property="Background"
                        Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"/>
                            <Setter Property="Foreground"
                        Value="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}"/>
                        </Trigger>
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="IsSelected"
                             Value="true"/>
                                <Condition Property="IsSelectionActive"
                             Value="false"/>
                            </MultiTrigger.Conditions>
                            <Setter TargetName="Bd"
                        Property="Background"
                        Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/>
                            <Setter Property="Foreground"
                        Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
                        </MultiTrigger>
                        <Trigger Property="IsEnabled"
                       Value="false">
                            <Setter Property="Foreground"
                        Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>


    <!-- Template for the columns tree view which contains a gridview header row presenter to add columns labels-->
    <Style TargetType="{x:Type l:ColumnsTreeView}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type l:ColumnsTreeView}">
                    <Border BorderBrush="{TemplateBinding BorderBrush}"
                    BorderThickness="{TemplateBinding BorderThickness}" >
                        <DockPanel >
                            <GridViewHeaderRowPresenter
                                Columns="{Binding Path=Columns,RelativeSource={RelativeSource TemplatedParent}}"
                                DockPanel.Dock="Top" />
                            <ScrollViewer 
                                CanContentScroll="True"
                                IsDeferredScrollingEnabled="True"
                                HorizontalScrollBarVisibility="Disabled" 
                                VerticalScrollBarVisibility="Visible" 
                                Visibility="Visible">
                                    <ItemsPresenter />
                            </ScrollViewer>
                        </DockPanel>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <!-- Data template for first cell in a row, we use this cell to create indentation and add the custom toggle button -->
    <DataTemplate x:Key="FirstCell">
        <DockPanel>
            <ToggleButton x:Name="Expander" 
                      Style="{StaticResource ExpandCollapseToggleStyle}" 
                      Margin="{Binding Path=Level,Converter={StaticResource LevelToIndentConverter},RelativeSource={RelativeSource AncestorType={x:Type l:ColumnsTreeViewItem}}}"
                      IsChecked="{Binding Path=IsExpanded, Mode=TwoWay, RelativeSource={RelativeSource AncestorType={x:Type l:ColumnsTreeViewItem}}}"
                      ClickMode="Press"
                          />
            <Image x:Name="StatusImage" Width="16" Height="16">
                <Image.Source>
                    <MultiBinding Converter="{StaticResource ThreadPostStatusConverter}">
                        <MultiBinding.Bindings>
                            <Binding />
                            <Binding Path="AreChildrenDisplayed" />
                            <Binding Path="ThreadIfRootPost.ThreadType" />
                            <Binding Path="ThreadIfRootPost.IsAnswered" />
                        </MultiBinding.Bindings>
                    </MultiBinding>
                </Image.Source>
            </Image>
            <TextBlock x:Name="Subject" Text="{Binding Path=Post.Subject}" ToolTip="{Binding Path=Post.Subject}"/>
            </DockPanel>
        <DataTemplate.Triggers>
            <DataTrigger Binding="{Binding Path=HasChildren}" 
                     Value="False">
                <Setter TargetName="Expander"
                  Property="Visibility"
                  Value="Hidden"/>
            </DataTrigger>

        </DataTemplate.Triggers>
    </DataTemplate>
</ResourceDictionary>